{
    // Starter App
    // angular.module is a global place for creating, registering and retrieving Angular modules
    // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
    // the 2nd parameter is an array of 'requires'

    angular.module('appModule')
        .config(appConfig)
        .run(appRun);
    appConfig.$inject = ['$stateProvider', '$urlRouterProvider', '$httpProvider', '$ionicConfigProvider'];
    appRun.$inject = ['$ionicPlatform', '$rootScope', '$ionicModal', '$ionicTabsDelegate', '$timeout', '$ionicHistory'];
    function appConfig($stateProvider, $urlRouterProvider, $httpProvider, $ionicConfigProvider) {
        if (ionic.Platform.isAndroid()) {
            // $ionicConfigProvider.views.transition('none');
            $ionicConfigProvider.tabs.position('bottom');
            $ionicConfigProvider.tabs.style('standard');
            $ionicConfigProvider.navBar.alignTitle('center');
        } else {
            $ionicConfigProvider.views.swipeBackEnabled(false);
        }
        $ionicConfigProvider.views.maxCache(12);
        /**拦截器**/
        $httpProvider.interceptors.push('http.sessionRecoverer');//用于Session失效的时候重新登录，并重发请求

        //==========以下是路由配置=====Start==============================================================================//
        $stateProvider
            .state('tab', {
                url: '/tab',
                abstract: true,
                templateUrl: './app/main/tabs.html',
                controller: 'MainController',
                controllerAs: 'vm'
            })
            .state('tab.overviews', {
                url: '/overviews',
                views: {
                    'tab-overviews': {
                        templateUrl: './app/overviews/overviews.html',
                        controller: 'OverviewsController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.emptyBed', {
                url: '/emptyBed',
                views: {
                    'tab-emptyBed': {
                        templateUrl: './app/emptyBed/emptyBed.html',
                        controller: 'EmptyBedController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.stayOutLate', {
                url: '/stayOutLate',
                views: {
                    'tab-stayOutLate': {
                        templateUrl: './app/stayOutLate/stayOutLate.html',
                        controller: 'StayOutLateController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.accommodationInquiry', {
                url: '/accommodationInquiry',
                views: {
                    'tab-accommodationInquiry': {
                        templateUrl: './app/accommodationInquiry/accommodationInquiry.html',
                        controller: 'AccommodationInquiryController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.studentInfo', {
                url: '/studentInfo/:id',
                views: {
                    'tab-accommodationInquiry': {
                        templateUrl: './app/accommodationInquiry/studentInfo.html',
                        controller: 'studentInfoController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.studentInfo1', {
                url: '/studentInfo1/:id',
                views: {
                    'tab-overviews': {
                        templateUrl: './app/accommodationInquiry/studentInfo.html',
                        controller: 'studentInfoController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.studentInfo2', {
                url: '/studentInfo2/:id',
                views: {
                    'tab-emptyBed': {
                        templateUrl: './app/accommodationInquiry/studentInfo.html',
                        controller: 'studentInfoController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.studentInfo3', {
                url: '/studentInfo3/:id',
                views: {
                    'tab-stayOutLate': {
                        templateUrl: './app/accommodationInquiry/studentInfo.html',
                        controller: 'studentInfoController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.dormitoryBuilding1', {
                url: '/dormitoryBuilding1/:id',
                views: {
                    'tab-overviews': {
                        templateUrl: './app/dormitoryBuilding/dormitoryBuilding.html',
                        controller: 'DormitoryBuildingController',
                        controllerAs: 'vm'
                    }
                }
            })
            /*个人*/
            .state('tab.studentPerson', {
                url: '/studentPerson/:id',
                views: {
                    'tab-studentPerson': {
                        templateUrl: './app/studentPerson/studentPerson.html',
                        controller: 'studentPersonController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.login', {
                url: '/login',
                views: {
                    'tab-login': {
                        templateUrl: './app/login/login.html',
                        controller: 'loginController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.studentStayOutLateList', {
                url: '/studentStayOutLateList/:id',
                views: {
                    'tab-stayOutLate': {
                        templateUrl: './app/studentStayOutLateList/studentStayOutLateList.html',
                        controller: 'studentStayOutLateListController',
                        controllerAs: 'vm'
                    }
                }
            })
            .state('tab.dormitoryBuilding2', {
                url: '/dormitoryBuilding2/:id',
                views: {
                    'tab-emptyBed': {
                        templateUrl: './app/dormitoryBuilding/dormitoryBuilding.html',
                        controller: 'DormitoryBuildingController',
                        controllerAs: 'vm'
                    }
                }
            });



        $urlRouterProvider.otherwise('/tab/login');
        //==========路由配置=====End======================================================================================//
    }

    function appRun($ionicPlatform, $rootScope, $ionicModal, $ionicTabsDelegate, $timeout, $ionicHistory) {
        /**
         * @desc 监听视图的进去,控制是否显示Tab
         */
        $rootScope.$on('$ionicView.beforeEnter', (scope, state)=> {
            let stateArr = [
                'tab.overviews', 'tab.emptyBed', 'tab.stayOutLate', 'tab.accommodationInquiry'
            ];
            if (stateArr.indexOf(state.stateName) < 0) {
                $ionicTabsDelegate.showBar(false);
            } else {
                $ionicTabsDelegate.showBar(true);
            }
        });
    }
}